package cn.life.business.audit.dao.impl;

import cn.life.business.audit.dao.AuditDao;
import cn.life.business.audit.entity.po.AuditPo;
import cn.life.common.support.jdbc.AbstractSupportDao;
import org.springframework.stereotype.Repository;

/**
 * @author 王振宇
 * @Description:
 * @Date 2018-09-20 16:32:03
 */
@Repository
public class AuditDaoImpl extends AbstractSupportDao implements AuditDao {

    @Override
    public int addAudit(AuditPo auditPo) {
        String sql= "insert into audit_info(apply_no,apply_id,audit_desc,audit_state,opr_user_id,opr_user_name,opr_date) values(?,?,?,?,?,?,?)";
        return update(sql,auditPo.getApplyNo(),auditPo.getApplyId(),auditPo.getAuditDesc(),auditPo.getAuditState(),
                auditPo.getOprUserId(),auditPo.getOprUserName(),auditPo.getOprDate());
    }

    @Override
    public int updateAudit(AuditPo auditPo) {
        String sql= "update audit_info set audit_state=?,apply_no=? where apply_id=?";
        return update(sql,auditPo.getAuditState(),auditPo.getApplyNo(),auditPo.getApplyId());
    }

    @Override
    public int updateState(AuditPo auditPo) {
        String sql= "update audit_info set audit_state=?,audit_desc=? where apply_id=?";
        return update(sql,auditPo.getAuditState(),auditPo.getAuditDesc(),auditPo.getApplyId());
    }

    @Override
    public AuditPo queryAuditInfo(AuditPo auditPo) {
        String sql = "select * from audit_info where apply_id = ?";
        return queryForObject(sql,AuditPo.class,auditPo.getApplyId());
    }

    @Override
    public void updateOnlyState(AuditPo auditPo) {
        String sql = "update audit_info set audit_state = 0 where apply_id = ?";
        update(sql,auditPo.getApplyId());
    }


}
